package com.invengo.testrfid.app.dao.base;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.invengo.testrfid.MyApplication;
import com.invengo.testrfid.app.dao.DaoMaster;
import com.invengo.testrfid.app.dao.DaoSession;

import org.greenrobot.greendao.identityscope.IdentityScopeType;


public class OperationDao {

    public static DaoSession daoSession;
    private static OperationDao operate;
    private static DaoMaster daoMaster;


    private OperationDao() {

        Context context = MyApplication.getContext();
        // 切换数据库
        String databaseName = "data";
        DataSQL helper = new DataSQL(context, databaseName, null);

        SQLiteDatabase db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);

        if (daoSession != null) {
            daoSession = daoMaster.newSession(IdentityScopeType.None);
        } else {
            daoSession = daoMaster.newSession();
        }

//		daoSession = daoMaster.newSession();
    }

    private OperationDao(String baseName) {

        Context context = MyApplication.getContext();
        DataSQL helper = new DataSQL(context, baseName, null);
        SQLiteDatabase db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);

        if (daoSession != null) {
            daoSession = daoMaster.newSession(IdentityScopeType.None);
        } else {
            daoSession = daoMaster.newSession();
        }
    }

    public static OperationDao getOperation() {

        if (operate == null) {
            operate = new OperationDao();
        }
        return operate;
    }
}
